{include file='public/head'}
<body>
<style media="screen" type="text/css">
    header {
        color: black;
    }
</style>
<div class="x-body">
    <form action="editRole" class="layui-form" id="mainForm" method="post" style="margin-right: 20px;">
        <input type="hidden" value="{$data.id}" name="id">

        <div class="layui-form-item">
            <label class="layui-form-label">角色名称</label>
            <div class="layui-input-block">
                <input autocomplete="off" value="{$data.title}" class="layui-input" id="title" lay-verify="required"
                       name="title" placeholder="请输入角色名称" type="text">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">启用状态</label>
            <div class="layui-input-block">
                <input type="radio" value="1" title="启用" name="status" {php} if($data['status']==1){echo 'checked';}
                {/php}>
                <input type="radio" value="0" title="禁用" name="status" {php} if($data['status']==0){echo 'checked';}
                {/php}>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input autocomplete="off" class="layui-input" id="sort" lay-verify="required" name="sort"
                       placeholder="数值越大越靠后" type="number" value="{$data.sort}" min="0">
            </div>
        </div>

        <div class="layui-form-item">
            <div>
                <button class="layui-btn" lay-filter="toSubmit" lay-submit="" style="width: 100%">提交保存</button>
            </div>
        </div>

    </form>
</div>
</body>
{include file='public/foot'}
<script type="text/javascript">
    var form = layui.form;
    var layer = layui.layer;
    //自定义验证规则
    form.verify({
        title: function (value) {
            if (value.length < 3) {
                return '标题至少得2个字符啊';
            }
        }
    });
    //监听提交
    form.on('submit(demo1)', function (data) {
        layer.alert(JSON.stringify(data.field), {
            title: '最终的提交信息'
        })
        return false;
    });
    $(document).ready(function () {
        var options = {
            type: 'post',           //post提交
            //url:'http://ask.tongzhuo100.com/server/****.php?='+Math.random(),   //url
            dataType: "json",        //json格式
            data: {},    //如果需要提交附加参数，视情况添加
            clearForm: false,        //成功提交后，清除所有表单元素的值
            resetForm: false,        //成功提交后，重置所有表单元素的值
            cache: false,
            async: false,          //同步返回
            success: function (data) {
                console.log(data);
                if (data.code == 0) {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                } else {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        $("#reset").click();
                        x_admin_close();
                        parent.location.reload();
                    });
                }
                //服务器端返回处理逻辑
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                layer.msg('操作失败:服务器处理失败');
            }
        };
        // bind form using 'ajaxForm' 
        $('#mainForm').ajaxForm(options).submit(function (data) {
            //无逻辑
        });

    });
</script>
 
